package com.xueyu.api;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class test {
    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
        String paidDate = "2024-01-07 15:37:02";
        int day = 1;
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 获取当前时间
        LocalTime currentTime = LocalTime.now();
        // 获取这个月的天数
        int currentMonthLength = currentDate.lengthOfMonth();


        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime paymentTime = LocalDateTime.parse(paidDate, formatter);

        LocalDateTime expiryTime = paymentTime.plusDays(day);

        Date expiryDate = Date.from(expiryTime.atZone(ZoneId.systemDefault()).toInstant());

        // 计算距离下个月还有多少天
        int daysToNextMonth = currentMonthLength - paymentTime.getDayOfMonth();

        String expireDate = sdf.format(expiryDate);
        System.out.println("时间"+expireDate);
        System.out.println(daysToNextMonth);
    }
}
